package manufacturerbeans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.SelectEvent;

@ManagedBean
@SessionScoped
public class BatchTable implements Serializable{
    private List<Batch> batches;
    private BatchDataModel batchDataModel;
    private Batch selectedBatch;

    public BatchTable() {
        batches = new ArrayList<Batch>();
        for (int i = 0; i < 10; i++) {
            String id=UUID.randomUUID().toString().substring(0, 8);  
            batches.add(new Batch(id,"desc",new Date()));
        }
        batchDataModel = new BatchDataModel(batches);
    }

    public Batch getSelectedBatch() {
        return selectedBatch;
    }

    public void setSelectedBatch(Batch selectedBatch) {
        this.selectedBatch = selectedBatch;
    }

    public BatchDataModel getBatches() {
        return batchDataModel;
    }

    public void onRowSelect(SelectEvent event) {
        FacesMessage msg = new FacesMessage("Batch Selected", ((Batch) event.getObject()).getName());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    
}
